package reflect;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

/**
 * 实例化10个Person对象
 * Person对象中的name顺序为:test1--test10
 * age顺序为:21-30
 * 并存入一个集合
 */
public class Test1 {
    public static void main(String[] args) throws Exception {
        List<Person> list = new ArrayList<>();

        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class,int.class);
        for (int i = 1; i <= 10; i++) {
            Object obj = c.newInstance("test"+(i),(i+20));
            System.out.println(obj);
            list.add((Person)obj);
        }
        System.out.println(list);
    }
}
